package com.nlabs.slickgwt.client;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ButtonBase;


public class SlickButton extends ButtonBase {
	
	private MouseHandler mh = new MouseHandler();  
	
	public SlickButton() {
		 
		super(DOM.createButton());
		layout();
	 
	 }
	 
	 public SlickButton(String s){
		 
		 super(DOM.createButton());
		 layout(); 
		 setHTML(s);
		 
		  
	 }
	 
	 
	 private void layout() {
		 
		 setStylePrimaryName("slick-button"); 
		 addMouseOverHandler(mh);
		 addMouseOutHandler(mh) ;
		 addMouseDownHandler(mh);
		 addMouseUpHandler(mh);
		 
	 }
	 
    private class MouseHandler implements MouseOverHandler, MouseOutHandler, MouseDownHandler, MouseUpHandler {
	
    	
    	public void onMouseOver(MouseOverEvent event) {
    		addStyleDependentName("hover");
		
    	}

    	public void onMouseOut(MouseOutEvent event) {
		 removeStyleDependentName("hover");
		
    	}

    	public void onMouseDown(MouseDownEvent event) {
		
    		event.preventDefault(); 
    		removeStyleDependentName("hover");
    		addStyleDependentName("active");
    		DOM.setCapture(getElement());
    	}

    	public void onMouseUp(MouseUpEvent event) {
		
    		removeStyleDependentName("active");
    		addStyleDependentName("hover");
    		DOM.releaseCapture(getElement());
    	}
    }

	 
	 
	 
 
	

}
